﻿<?php
error_reporting(0);
define('IN_QY',true);
session_start();
require("include/common.inc.php");
require_once("include/config.php");
require_once("include/httpUtil.php");
define('SCRIPT','ad_list');

$total_fee=trim($_GET['total_fee']);

if($_GET['bill']!=""){
$infoid=$_GET['bill'];
$orderid =$_GET['bill'];		
}else{
	
$infoid=$_GET['out_trade_no'];
$orderid =$_GET['out_trade_no'];	
}

//
 $sql_user="select * from tbl_taorder where orderid='".$infoid."'  order by id desc  limit 1  " ;
 $queryuser=mysql_query($sql_user);
 $row=mysql_fetch_array($queryuser);
 
  $sqls="select * from tbl_taospp where  id='".$row['goodid']."'  order by id desc  limit 1  " ;
 $querys=mysql_query($sqls);
 $rows=mysql_fetch_array($querys);
 
 
 //
  $ff=$total_fee;
 $c=$row['uid'];
 
 if ($row['is_pay']==1) {
	echo "<script type='text/javascript'>alert('此订单已支付！');location.href='/wap/my.php';</script>";
    exit;
}
 
 
 //更新订单为已付款
 $sqlw = "update tbl_taorder set is_pay=1, paytime='".time()."' where orderid='".$orderid."'";
mysql_query($sqlw);

  /*********************写入账单**********************/
			$sqlu = "select * from tbl_user where id=".$row['uid'];
            $queryu=mysql_query($sqlu);
            $rowu=mysql_fetch_array($queryu);
            $jifen = $rowu['jifen'];
            $yuee = $rowu['yuee'];
            $xyf = $rowu['xyf'];
            $mobile = $rowu['userid'];
            $shuyu = $rowu['shuyu'];
			$is_vip = $rowu['is_vip'];
			
			$sqly = "insert into tbl_zhangdan values (0,'海淘付款','".$ff."','".$jifen."','".$xyf."',0,'".$yuee."','".date('Y-m-d H:i:s')."','".$row['uid']."','".$row['orderid']."',1,0)";
	             mysql_query($sqly);

 //短信发送开始--承租方
$funAndOperate = "industrySMS/sendSMS";
// 生成body
$body = createBasicAuthData();
// 在基本认证参数的基础上添加短信内容和发送目标号码的参数
$body['smsContent'] = '【众晒网】亲爱的'.$_COOKIE['shuyu'].'，您好！我们已经收到您订单'.$total_fee.'的付款，我们会在第一时间为您配送发货，请耐心等待哦！';
$body['to'] = ''.$mobile.'';
$result = post($funAndOperate, $body);

/*********************加积分*********************/	

if($is_vip==1){

$jifen_fan=	$row['totprice'];

$vip_fan=0;
}else{
	
$jifen_fan=	$row['totprice']*0.5;
	
$vip_fan=	$row['totprice']*0.02;

}

//积分+;返现
$sqlyu = "update tbl_user set jifen=jifen+'".$jifen_fan."',fanxian=fanxian+'".$vip_fan."'  where id=".$c;
mysql_query($sqlyu);
//返现余额

$sql = "select jifen from tbl_user where id=".$c;
$query = mysql_query($sql);
$rowji = mysql_fetch_array($query);

$conten = "海淘送积分";
$sqltji = "insert into tbl_zhangdan values (0,'".$conten."','".$newyu."','".$rowji['jifen']."',0,1,0,'".date("Y-m-d H:i:s")."','".$c."','".$orderid."',0,2)";
mysql_query($sqltji);
//下架

 $sql_userr="select * from tbl_taorder where orderid='".$infoid."'" ;
 $queryuserr=mysql_query($sql_userr);
   while ($rowr=mysql_fetch_array($queryuserr)) {

   
   $sql = "select jifen from tbl_spp where id='".$rowr['goodid']."'";
$query = mysql_query($sql);
$rowji = mysql_fetch_array($query);
   
   
   
$sqlyu = "update tbl_spp set state=0  where id='".$rowji['id']."'";
mysql_query($sqlyu);




   }

//



//zouni 
if($rows['goodstype']<4){
	
echo "<script type='text/javascript'>alert('支付成功');location.href='/wap/my.php';</script>";	

}
   




?>






	<script type="text/javascript" src="/ui/xianzhi/js/jquery.min.js"></script>

    <script type="text/javascript" src="/ui/layer/mobile/layer.js"></script>  
	
	 <?php if($rows['goodstype']>3){ ?>
  	<script>

		var pay_type=2;
		var uid='<?=$_COOKIE['userid']?>';
		var goodsid='<?=$rows['id']?>';
		console.log(pay_type);
		console.log(uid);
		console.log(goodsid);		
	    $.ajax({
        url: '/api/muyin/api.php?s=user.pay_vip_use_score',
        type: 'POST',
        dataType: 'json',
        data: {goodsid: goodsid,
		uid:uid,
		pay_type:pay_type	
		},
      });

alert("支付成功");
	  
location.href='/wap/my.php';		

	


	
	</script>

		<?php }  ?>






